//
//  PoolListTableVC.m
//  duoduo
//
//  Created by wanghao on 16/10/13.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "PoolListTableVC.h"
#import "DCPicScrollView.h"
#import "PoolListCell.h"
#import "Poolinfo_ViewController.h"
#import "Pool_infoVC.h"
#import "PoolOneCell.h"
#import "LineViewController.h"

@interface PoolListTableVC ()<UITextFieldDelegate>
{
    //轮播图的数据
    NSArray *cycleImageArr;
    UIView *headerView;
    NSArray * fromArr;
    NSArray * toArr;
    NSArray * priceArr;
}

@end

@implementation PoolListTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    cycleImageArr = @[@"banner@2x",@"banner@2x",@"banner@2x"];
    fromArr = @[@"深圳南山",@"深圳西乡",@"深圳宝安",@"深圳宝安",@"深圳坪洲"];
    toArr = @[@"东莞虎门",@"深圳罗湖",@"广东惠州",@"深圳罗湖",@"广州番禺"];
    priceArr = @[@"¥ 88/人",@"¥ 38/人",@"¥ 108/人",@"¥ 35/人",@"¥ 128/人"];

    [self initUI];
}

- (void)initUI
{
    headerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 150)];
    headerView.backgroundColor =[UIColor whiteColor];

    self.tableView.tableFooterView.backgroundColor = LXHexColor(0xD6D6D6);
    [self.tableView registerNib:[UINib nibWithNibName:@"PoolListCell" bundle:nil] forCellReuseIdentifier:@"listcell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"PoolOneCell" bundle:nil] forCellReuseIdentifier:@"onecell"];
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self getTableHeaderView:cycleImageArr];
}

#pragma mark- TableViewHead
-(void)getTableHeaderView:(NSArray *)arr
{
    DCPicScrollView  *picView = [DCPicScrollView picScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, 150) WithImageUrls:arr];
    [headerView addSubview:picView];
    self.tableView.tableHeaderView = headerView;

}

- (void)searchClick
{
    LineViewController * searchVC = [[LineViewController alloc]init];
    [self.navigationController pushViewController:searchVC animated:YES];
}

#pragma mark -- textFieldShouldReturn
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.tableView endEditing:YES];
    return YES;
}

#pragma mark --- UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return fromArr.count+1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        PoolOneCell * cell = [tableView dequeueReusableCellWithIdentifier:@"onecell"];
        [cell.searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
        cell.myLocationText.delegate = self;
        return cell;
    }else{
        PoolListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"listcell"];
        cell.fromAddressLabel.text = fromArr[indexPath.section-1];
        cell.toAddressLabel.text = toArr[indexPath.section-1];
        cell.priceLabel.text = priceArr[indexPath.section-1];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section>0) {
        Poolinfo_ViewController * vc = [[Poolinfo_ViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else if (section == 1) {
        return 30;
    }
    return 15;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
        view.backgroundColor = LXHexColor(0xF5F6F7);
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 150, 18)];
        label.textColor = [UIColor grayColor];
        label.text = @"我附近的线路";
        label.font = [UIFont systemFontOfSize:15];
        [view addSubview:label];
        return view;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 155;
    }else{
        return 80;
    }
    
}

@end
